2d array - ds hackerrank solution in java